package com.hs.biye.controller.admin;

import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.BedRequest;
import com.hs.biye.model.DTO.InhospitalRequest;
import com.hs.biye.model.VO.BedVo;
import com.hs.biye.model.VO.InhospitalVo;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.BedService;
import com.hs.biye.service.InhospitalService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@RestController
@RequestMapping("/admin/inhospital")
public class InHospitalController {
    @Resource
    private InhospitalService inhospitalService;

    //查询住院信息信息
    @PostMapping("/pages")
    public ResultPage<InhospitalVo> getInhospitalPage(@RequestBody InhospitalRequest inhospitalRequest){
        if (inhospitalRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        return inhospitalService.getPageInhospital(inhospitalRequest);
    }


    //根据id查询住院信息信息
    @PostMapping("/one/{id}")
    public Result<InhospitalVo> getInhospitlById(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        return Result.success(inhospitalService.getPageInhospitalById(id)) ;
    }


    //添加
    @PostMapping("/add")
    public Result<Boolean> addInhospital(@RequestBody InhospitalRequest inhospitalRequest){
        if (inhospitalRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = inhospitalService.addInhospital(inhospitalRequest);
        return Result.success(res);
    }



    //修改
    @PostMapping("/update")
    public Result<Boolean> updateInhospital(@RequestBody InhospitalRequest inhospitalRequest){
        if (inhospitalRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = inhospitalService.updateInhospital(inhospitalRequest);
        return Result.success(res);
    }

    //删除
    @GetMapping("/delete/{id}")
    public Result<Boolean> deleteById(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = inhospitalService.removeInhospital(id);
        return Result.success(res);
    }

    //出院
    @GetMapping("/out/{id}")
    public Result<Boolean> OutHospital(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = inhospitalService.OutHospital(id);
        return Result.success(res);
    }


}
